const express = require('express');
const router = express.Router();

// 模拟近期自习室活动数据
const recentActivities = [{
		id: 1,
		activityName: '高效自习挑战活动',
		activityTime: '2024-11-15 14:00 - 16:00',
		participantCount: 25,
		activityImage: 'https://example.com/activity1.jpg'
	},
	{
		id: 2,
		activityName: '学习方法分享会',
		activityTime: '2024-11-20 19:00 - 21:00',
		participantCount: 18,
		activityImage: 'https://example.com/activity2.jpg'
	},
	{
		id: 3,
		activityName: '夜间自习马拉松',
		activityTime: '2024-11-25 20:00 - 23:00',
		participantCount: 30,
		activityImage: 'https://example.com/activity3.jpg'
	},
	{
		id: 4,
		activityName: '英语角沉浸式学习',
		activityTime: '2024-12-01 15:30 - 17:30',
		participantCount: 22,
		activityImage: 'https://example.com/activity4.jpg'
	},
	{
		id: 5,
		activityName: '考研冲刺特训营',
		activityTime: '2024-12-10 09:00 - 12:00',
		participantCount: 15,
		activityImage: 'https://example.com/activity5.jpg'
	},
	{
		id: 6,
		activityName: '编程实战工作坊',
		activityTime: '2024-12-15 13:00 - 18:00',
		participantCount: 28,
		activityImage: 'https://example.com/activity6.jpg'
	}
];

// 获取近期自习室活动列表的接口
router.get('/recentActivities', (req, res) => {
	try {
		res.json({
			success: true,
			message: '获取近期自习室活动列表成功',
			data: recentActivities
		});
	} catch (error) {
		res.status(500).json({
			success: false,
			message: '服务器内部错误',
			error: error.message
		});
	}
});

// 根据活动 ID 获取单个活动信息的接口
router.get('/recentActivities/:id', (req, res) => {
	const activityId = parseInt(req.params.id);
	const activity = recentActivities.find(act => act.id === activityId);

	if (!activity) {
		return res.status(404).json({
			success: false,
			message: '未找到该活动'
		});
	}

	try {
		res.json({
			success: true,
			message: '获取活动信息成功',
			data: activity
		});
	} catch (error) {
		res.status(500).json({
			success: false,
			message: '服务器内部错误',
			error: error.message
		});
	}
});

module.exports = router;